$(function () {
	var module = 'DepartmentQfLeaveMe';
	var urlPrefix = '/department/leave/me/';
	// 定义加载列表的函数
	function loadList (options) {
		PSys.loadList(Object.assign({
			module : module,
			url : urlPrefix + 'list'
		}, options));
	}
	// 加载列表
	loadList();
	
	// 设置申请按钮点击事件
	$('body').on ('click', '#btnDepartmentQfLeaveApply', function () {
		PSys.loadForm ({
			title : '申请',
			url : '/department/leave/me/apply'
		});
	});
	
	// 设置申请页面的提交按钮事件
	$('body').on ('click', '#btnDepartmentQfLeaveApplyFormSubmit', function () {
		PSys.submitForm({
			formSelector : '#formDepartmentQfLeaveApply',
			url : '/department/leave/me/apply',
			callback : function () {
				loadList();
			}
		});
	});
	
	// 设置处理/查看按钮的点击事件
	$('body').on ('click', '.table a', function () {
		var id = $(this).parent().parent().find('input').val();
		PSys.loadForm ({
			title : '处理/查看',
			url : '/department/leave/me/process?id=' + id
		});
	});
	
	// 设置流程处理页面的提交按钮事件
	$('body').on ('click', '#btnDepartmentQfLeaveMeProcessFormSubmit', function () {
		// 默认提交部门审批form
		var cfg = {
			formSelector : '#formDepartmentQfLeaveMeManager',
			url : '/department/leave/me/manager',
			callback : function () {
				loadList();
			}
		};
		// 如果人事确认form存在，则提交该form
		if ($('#formDepartmentQfLeaveMeHR').length == 1) {
			cfg.formSelector = '#formDepartmentQfLeaveMeHR';
			cfg.url = '/department/leave/me/hr';
		}
		// 如果CEO审批form存在，则提交该form
		if ($('#formDepartmentQfLeaveMeCEO').length == 1) {
			cfg.formSelector = '#formDepartmentQfLeaveMeCEO';
			cfg.url = '/department/leave/me/ceo';
		}
		PSys.submitForm(cfg);
	});
	
	// 设置流程处理页面的取消按钮事件
	$('body').on ('click', '#btnDepartmentQfLeaveMeProcessFormCancel', function () {
		PSys.removeTopAdminDiv();
	});
});